<template>
  <div class="app-container">
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="广告ID" width="95">
        <template slot-scope="scope">
          {{ scope.row.advertisingId }}
        </template>
      </el-table-column>
      <el-table-column label="广告图片">
        <template slot-scope="scope">
          <img :src="scope.row.advertisingImg" width="120px">
<!--          {{ scope.row.advertisingImg }}-->
        </template>
      </el-table-column>
      <el-table-column label="对应的商品ID" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.goodsId }}</span>
        </template>
      </el-table-column>
      <el-table-column label="广告状态" width="110" align="center">
        <template slot-scope="scope">
          {{ scope.row.advertisingState }}
        </template>
      </el-table-column>
      <el-table-column align="center" prop="created_at" label="Display_time" width="200">
        <template slot-scope="scope">
          <i class="el-icon-time" />
          <span>{{ scope.row.createTime }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作"  align="center">
        <template slot-scope="scope">
          <el-button type="danger" icon="el-icon-delete" circle @click="idDel(scope.row.advertisingId)"> </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
// import { getList } from '@/api/table'
import { listApi,DelApi } from '@/api/server-advertisement'


export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      listLoading: true
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    // 根据id删除
    idDel(id) {
      var that = this;
      DelApi(id,function(msg) {
        alert(msg.msg)
        if(msg.msg == '删除成功'){
          that.fetchData()
        }

      })
    },
    fetchData() {
      var that = this
      that.listLoading = true
      listApi(function(msg) {
        console.log(msg);
        that.list = msg.data;
        if (msg.msg === '查询成功！') {
          that.listLoading = false
        }
      })


      // this.listLoading = true
      // getList().then(response => {
      //   this.list = response.data.items
      //   this.listLoading = false
      // })
    }
  }
}
</script>
